import React from 'react'
import PropTypes from "prop-types"
import { NavBar } from "antd-mobile"
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
import "./NavBarAgain.less"

export default function NavBarAgain(props) {
  const navigate = useNavigate()
  let { title } = props;
  let location = useLocation(),
    [search] = useSearchParams();
  let to = search.get("to")

  const back = () => {
    if (location.pathname == "/login" && to && to.indexOf("/detail") !== -1) {
      navigate(to, { replace: true })
    } else {
      navigate(-1)
    }
  }

  return (
    <NavBar className='navbar-again-box' onBack={back}>{title}</NavBar>
  )
}

NavBarAgain.defaultProps = {
  title: "个人中心"
};

NavBarAgain.propTypes = {
  title: PropTypes.string
}
